package com.server.questionbank.snframe.mapper.Course;

import com.server.questionbank.snframe.domain.TInterest;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TInterestMapper {
    // 获取用户加入的课程标签
    @Select("SELECT course_type.type_id AS target_id, (#{userId}) AS user_id, ('type') AS target_type, user_regist_cus.regist_time AS create_date " +
            "FROM course_type " +
            "JOIN course_type_mapping ON course_type.type_id = course_type_mapping.type_id " +
            "JOIN user_regist_cus ON course_type_mapping.course_id = user_regist_cus.course_id " +
            "WHERE user_regist_cus.user_id = #{userId} " +
            "ORDER BY user_regist_cus.regist_time DESC")
    public List<TInterest> getCourseTypeByJoinUserId(@Param("userId") Long userId);

    // 获取用户创建的课程标签
    @Select("SELECT course_type.type_id AS target_id, (#{userId}) AS user_id, ('type') AS target_type, T_course.create_date AS create_date " +
            "FROM course_type " +
            "JOIN course_type_mapping ON course_type.type_id = course_type_mapping.type_id " +
            "JOIN T_course ON course_type_mapping.course_id = T_course.course_id " +
            "WHERE T_course.create_by = #{userId} " +
            "ORDER BY T_course.create_date DESC")
    public List<TInterest> getCourseTypeByCreateUserId(@Param("userId") Long userId);

    // 获取用户收藏的课程标签
    @Select("SELECT course_type.type_id AS target_id, (#{userId}) AS user_id, ('type') AS target_type, T_collection.create_date AS create_date " +
            "FROM course_type " +
            "JOIN course_type_mapping ON course_type.type_id = course_type_mapping.type_id " +
            "JOIN T_collection ON course_type_mapping.course_id = T_collection.target_id " +
            "WHERE T_collection.user_id = #{userId} " +
            "ORDER BY T_collection.create_date DESC")
    public List<TInterest> getCourseTypeByCollectUserId(@Param("userId") Long userId);

    // 获取用户加入的课程标签
    @Select("SELECT course_label.label_id AS target_id, (#{userId}) AS user_id, ('label') AS target_type, user_regist_cus.regist_time AS create_date " +
            "FROM course_label " +
            "JOIN course_label_mapping ON course_label.label_id = course_label_mapping.label_id " +
            "JOIN user_regist_cus ON course_label_mapping.course_id = user_regist_cus.course_id " +
            "WHERE user_regist_cus.user_id = #{userId} " +
            "ORDER BY user_regist_cus.regist_time DESC")
    public List<TInterest> getCourseLabelByJoinUserId(@Param("userId") Long userId);

    // 获取用户创建的课程标签
    @Select("SELECT course_label.label_id AS target_id, (#{userId}) AS user_id, ('label') AS target_type, T_course.create_date AS create_date " +
            "FROM course_label " +
            "JOIN course_label_mapping ON course_label.label_id = course_label_mapping.label_id " +
            "JOIN T_course ON course_label_mapping.course_id = T_course.course_id " +
            "WHERE T_course.create_by = #{userId} " +
            "ORDER BY T_course.create_date DESC")
    public List<TInterest> getCourseLabelByCreateUserId(@Param("userId") Long userId);

    // 获取用户收藏的课程标签
    @Select("SELECT course_label.label_id AS target_id, (#{userId}) AS user_id, ('label') AS target_type, T_collection.create_date AS create_date " +
            "FROM course_label " +
            "JOIN course_label_mapping ON course_label.label_id = course_label_mapping.label_id " +
            "JOIN T_collection ON course_label_mapping.course_id = T_collection.target_id " +
            "WHERE T_collection.user_id = #{userId} " +
            "ORDER BY T_collection.create_date DESC")
    public List<TInterest> getCourseLabelByCollectUserId(@Param("userId") Long userId);

}
